package net.huashitong.supervision.AppNew.appCtrl;

import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.Message;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.supervision.AppNew.DTO.viewDto.NumCount;
import net.huashitong.supervision.AppNew.OverdueDept;
import net.huashitong.supervision.AppNew.appService.AppHomeService;
import net.huashitong.supervision.AppNew.appService.OverDueDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping(value = "/app/home")
public class AppHomeViewCtrl extends JsonBaseController {

    @Autowired
    private AppHomeService homeService;

    @Autowired
    private OverDueDeptService overDueDeptService;
    @Override
    protected String getView(String s) {
        return null;
    }



    /**
     * 主任务统计个数
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/taskNum",method = RequestMethod.GET)
    public Message getSendandFinsh()
    {
        HashMap<String, Integer> total = homeService.getSendAndFinishNum();

        return coverMessage("200","首页总数统计",total);
    }

    /**
     * 事项类型统计
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/taskcatenum",method = RequestMethod.GET)
    public Message taskCateNum()
    {
        List<NumCount> numCounts = homeService.getcategoryNums();

        return coverMessage("200","事项类型统计",numCounts);
    }

    /**
     * 一周统计
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/weektask",method = RequestMethod.GET)
    public Message weekTask()
    {
        HashMap<String, Integer> weekUnitTask = homeService.getWeekUnitTask();

        return coverMessage("200","一周统计",weekUnitTask);
    }

    /**
     *
     * @param year
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/overduedept",method = RequestMethod.GET)
    public Message overdueDeot(String year)
    {
        if(StringUtils.isBlank(year))
        {
            year="2021";
        }
        List<OverdueDept> query = overDueDeptService.getOverDept(year);
        return coverMessage("200","逾期单位数量",query);
    }






}
